package com.zcup.designer.behavior.observer;

import java.util.ArrayList;
import java.util.List;

public class ConcreteSubject extends Subject{
    public int subjectState;
    private final List<Observer> observerList = new ArrayList<>();
    public ConcreteSubject(int subjectState) {
        this.subjectState = subjectState;
    }

    @Override
    void attach(Observer observer) {
        observerList.add(observer);
    }

    @Override
    void detach(Observer observer) {
        observerList.remove(observer);
    }

    @Override
    void notifyObserver() {
        for (Observer observer : observerList) {
            observer.update();
        }
    }
}
